<?php

namespace app\apiadmin\controller\liveManager;

use app\apiadmin\model\liveManager\LiveManagerModel;
use app\apiadmin\service\behavior\ControlService;
use app\apiadmin\service\behavior\MarketionService;
use app\apiadmin\service\liveManager\LiveManagerService;
use app\apiadmin\service\statics\LiveUserGetDataService;
use app\apiadmin\service\TCSS\TImService;
use Predis\Client;

class LiveStatus
{

    private $_liveId;
    private $_info;
    private $_redis;

    private $_operaId;

    private $_command_array = [
        "showPopCard", // 显示弹卡
        "showHotSale", // 显示热卖
        "showStock", // 显示库存
        "showNickName", // 隐藏昵称
        "showOnlineCount", // 显示在线人数
        "showLittleYellowCar", // 显示小黄车
        "showCourseSellStatus",//显示商品已售罄
        "showDigitMan", // 隐藏数字人/评论组
        "showAllSilence", // 全体禁言
        "sendGongGao", // 添加公告
        "sendXiaoHeiBan", // 添加小黑板
    ];

    public function __construct($liveId, $operaId = 0)
    {
        if (!empty($liveId)) {
            $this->_liveId = $liveId;
            // 加载 直播场次
            $info = LiveManagerModel::find($liveId);
            if (empty($info)) {
                throw new \Exception("直播场次不存在");
            }
            $this->_info = $info;
        }
        $this->_redis = new Client([
            'scheme' => 'tcp',
            'host' => env('redis.host'),
            'port' => env('redis.port'),
            'password' => env('redis.password'),
            "username" => env('redis.username'),

        ]);

        $this->_operaId = $operaId;
    }

    /**
     * 获取 redis 中的 状态key
     *
     * @param string $liveId
     * @return string
     */
    private function getLiveKey($liveId)
    {
        // $group_id = $this->GetGroupIdByLiveId($liveId);
        return env("redis.prefix") . "live:list:" . $liveId . ":" . "status";
    }

    public function SetLiveIdAndGroupId($liveId, $groupId)
    {
        // 同时写入一个livdid 和 groupId
        $keyForLiveId = env("redis.prefix") . "live:map:liveid:" . $liveId;
        $keyForGroupId = env("redis.prefix") . "live:map:groupid:" . $groupId;

        $this->_redis->set($keyForLiveId, $groupId);
        $this->_redis->set($keyForGroupId, $liveId);
    }

    public function GetLiveIdByGroupId($groupId)
    {
        $keyForGroupId = env("redis.prefix") . "live:map:groupid:" . $groupId;
        $ret = $this->_redis->get($keyForGroupId);
        if (empty($ret)) {
            throw new \Exception("GetLiveIdByGroupId:" . $groupId . ":error");
        }
        return $ret;
    }

    public function GetGroupIdByLiveId($liveId)
    {
        $keyForLiveId = env("redis.prefix") . "live:map:liveid:" . $liveId;
        $ret = $this->_redis->get($keyForLiveId);
        if (empty($ret)) {
            throw new \Exception("GetGroupIdByLiveId:" . $liveId . ":error");
        }
        return $ret;
    }

    public function getLiveStatus()
    {
        $key = $this->getLiveKey($this->_liveId);
        return $this->_redis->hgetall($key);
    }
    

    public function addLikely($liveId, $number = 0)
    {
        $key = env("redis.prefix") . "live:list:" . $liveId . ":" . "likely";
        if (empty($number)) {
            return $this->_redis->incr($key);
        }
        return $this->_redis->incrby($key, $number);
    }

    public function getLikely($liveId)
    {
        $key = env("redis.prefix") . "live:list:" . $liveId . ":" . "likely";
        return $this->_redis->get($key);
    }

    public function getVMCount($liveId)
    {

        $key = env("redis.prefix") . "live:list:" . $liveId . ":status";
        $key2 = "showOnlineCount";

        $ret = $this->_redis->hget($key, $key2);

        $vm = json_decode($ret);
        if (!empty($vm) && !empty($vm->num)) {
            return $vm->num;
        } else {
            return 0;
        }
    }

    public function setLikely($liveId, int $count)
    {
        $key = env("redis.prefix") . "live:list:" . $liveId . ":" . "likely";
        return $this->_redis->set($key, $count);
    }
    
    //设置售罄商品列表
    public function setSellOutGoodIdList($liveId,$goods_ids){
        $key = env("redis.prefix") . "live:list:" . $liveId . ":" . "sell_out_goods_id_list";
        return $this->_redis->set($key, $goods_ids);
    }
    //获取售罄商品列表
    public function getSellOutGoodIdList($liveId){
        $key = env("redis.prefix") . "live:list:" . $liveId . ":" . "sell_out_goods_id_list";
        return $this->_redis->get($key);
    }
    
    public function setGoodIdList($liveId, array $goodIdList)
    {
        $key = env("redis.prefix") . "live:list:" . $liveId . ":" . "goods_id_list";
        return $this->_redis->lpush($key, $goodIdList);
    }

    public function getGoodIdList($liveId)
    {
        $key = env("redis.prefix") . "live:list:" . $liveId . ":" . "goods_id_list";
        return $this->_redis->lrange($key, 0, -1);
    }
    public function setGoodSaleCount($liveId, int $goodId, $count = 1)
    {
        $key = env("redis.prefix") . "live:list:" . $liveId . ":" . $goodId . ":" . "sale_count";
        return $this->_redis->incrby($key, $count);
    }
    public function getGoodSaleCount($liveId, int $goodId)
    {
        $key = env("redis.prefix") . "live:list:" . $liveId . ":" . $goodId . ":" . "sale_count";
        $ret = $this->_redis->get($key);
        if (empty($ret)) {
            return 0;
        }
        return $ret;
    }

    public function setGoodsSaleAmount($liveId, int $goodId, int $amount = 1)
    {
        $key = env("redis.prefix") . "live:list:" . $liveId . ":" . $goodId . ":" . "sale_amount";
        return $this->_redis->incrby($key, $amount);
    }

    public function getGoodsSaleAmount($liveId, int $goodId)
    {
        $key = env("redis.prefix") . "live:list:" . $liveId . ":" . $goodId . ":" . "sale_amount";
        $ret = $this->_redis->get($key);
        if (empty($ret)) {
            return 0;
        }
        return $ret;
    }

    public function getGoodStatusInfo($liveId)
    {
        $IdList = $this->getGoodIdList($liveId);
        $ReturnInfo = [];
        $keys = [];
        array_walk($IdList, function ($goodId) use (&$keys, $liveId) {
            $keys[] = env("redis.prefix") . "live:list:" . $liveId . ":" . $goodId . ":" . "sale_count";
            $keys[] = env("redis.prefix") . "live:list:" . $liveId . ":" . $goodId . ":" . "sale_amount";
        });

        $ret = $this->_redis->mget($keys);
        array_walk($IdList, function ($value, $key) use (&$ReturnInfo, $ret) {
            $key2 = $key * 2;
            $ReturnInfo[$value] = [
                "count" => empty($ret[$key2]) ? 0 : $ret[$key2],
                "amount" => empty($ret[$key2 + 1]) ? 0 : $ret[$key2 + 1],
            ];
        });

        return $ReturnInfo;

    }

    public function ProcessCmd($cmd, $params)
    {
        switch ($cmd) {
            case "showPopCard":
                // 显示/隐藏弹卡
                return $this->showPopCard($params);
            case "showPopUp":
                // 显示/隐藏弹窗
                return $this->showPopUp($params);
            case "showHotSale":
                // 显示热卖
                return $this->showHotSale($params);
            case "showStock":
                // 显示仅剩库存
                return $this->showStock($params);
            case "showNickName":
                // 显示/隐藏昵称
                return $this->showNickName($params);
            case "showOnlineCount":
                // 设置初始在线人数
                return $this->showOnlineCount($params);
            case "showLittleYellowCar":
                // 显示/隐藏小黄车
                return $this->showLittleYellowCar($params);
            case "showCourseSellStatus":
                // 显示/隐藏商品已售罄按钮
                return $this->showCourseSellStatus($params);
            case "showDigitMan":
                // 显示/隐藏数字人/评论组
                return $this->showDigitMan($params);
            case "showAllSilence":
                // 全体禁言 
                return $this->showAllSilence($params);
            case "customStatus":
                return $this->customStatus($params);
            case "sendCommand":
                return $this->sendCommand($params);
            case "sendMessage":
                // 数字人评论
                return $this->sendMsg($params);
            case "getOnCar":
                // 正在购买(浏览小黄车)
                return MarketionService::addOrEdit($params);
            case "getPay":
                // 数字人下单
                return MarketionService::addOrEdit($params);
            case "getSignIn":
                // 数字人进场
                return MarketionService::addOrEdit($params);
            case "setDefaultStatus":
                return $this->setDefaultStatus($params);
            case "forbidUser":
                // 禁言/解禁
                return $this->forbidUser($params);
            case "offLive":
                // 关闭直播
                $this->closeIt($params);
                return ControlService::addOrEdit($params);
            case "hideMsg":
                // 隐藏/显示消息
                return $this->hideMsg($params);
            case "sendGongGao":
                // 发送公告信息，评论区显示
                return $this->addGongGao($params);
            case "sendXiaoHeiBan":
                // 发送小黑板信息
                return $this->addXiaoHeiBan($params);
            case "hideXiaoHeiBan":
                // 隐藏小黑板信息 
                return $this->hideXiaoHeiBan($params);
            case "sendPrivateMessage":
                // 发送私聊 
                return $this->sendPrivateMessage($params);
            case "ChoujiangStatus":
                //显示抽奖信息
                return $this->ChoujiangStatus($params);
            case "KaiJiangStatus":
                //显示抽奖信息
                return $this->KaiJiangStatus($params);
            case "FinishStatus":
                //显示抽奖信息
                return $this->FinishStatus($params);
            default:
                throw new \Exception("cmd not found [" . $cmd . "]");
        }

    }
    
    public function sendPrivateMessage($param)
    {
        // 发送私聊
        $tim = new TImService("administrator");
        return $tim->message_admin_to_user($this->_liveId, $param);
    }
    
    public function showAllSilence($param)
    {
        // 全体禁言
        $key = $this->getLiveKey($this->_liveId);
        return $this->_redis->hset($key, "showAllSilence", json_encode($param));
    }

    public function closeIt($params)
    {
        // 关闭直播
        $liveId = $params['liveId'];

        $liveManager = new LiveManagerService();
        $liveManager->updateStatusByTaskId($liveId, 2, time());

    }

    public function hideXiaoHeiBan($params){
        $collection = 'live_blackboard';
        //添加公告
        $lugs = new LiveUserGetDataService($collection);

        $map = [];
        $map['liveId'] = $params['liveId'];
        $map['show'] = false;
        $map['send_time'] = time() - strtotime(self::get_live_starttime()); //相对于开播时间
        $lugs->addBlackBoard($map);
    }

    public function addXiaoHeiBan($params){
        $collection = 'live_blackboard';
        //添加公告
        $lugs = new LiveUserGetDataService($collection);

        $map = [];
        $map['liveId'] = $params['liveId'];
        $map['txt'] = $params['txt'];
        $map['show'] = $params['show'];
        $map['imgList'] = $params['imgList'];
        $map['tutor_name'] = $params['tutor_name'];
        $map['tutor_id'] = $params['tutor_id'];
        $map['send_time'] = time() - strtotime(self::get_live_starttime()); //相对于开播时间
        $lugs->addBlackBoard($map);

        //记入初始化缓存
        $key = $this->getLiveKey($this->_liveId);
        $this->_redis->hset($key, "sendXiaoHeiBan", json_encode($map));
    }

    public function addGongGao($params)
    {

        $collection = 'live_notice';
        //添加公告
        $lugs = new LiveUserGetDataService($collection);

        $map = [];
        $map['liveId'] = $params['liveId'];
        $map['txt'] = $params['txt'];
        $map['tutor_name'] = $params['tutor_name'];
        $map['tutor_id'] = $params['tutor_id'];
        $map['send_time'] = time() - strtotime(self::get_live_starttime()); //相对于开播时间
        $lugs->addGongGao($map);

    }

    public function hideMsg($params)
    {
        // 隐藏/显示消息 mongo入库
        ControlService::addOrEdit($params);
        $chartId = $this->_info["chatroom_group_id"];
        $tim = new TImService();
        $tim->redis_set_online_msg($chartId, $params['user']['no'], $params['user']);
        $ret = $tim->redis_set_hide_msg($chartId, $params['user']['no'], $params['user']);
        if ($ret) {
            return true;
        } else {
            throw new \Exception("发生错误!");

        }
    }

    public function forbidUser($params)
    {
        // 禁言/解禁 mongo入库
        ControlService::addOrEdit($params);

        if (empty($params["userIds"]) || !is_int($params["time"]) || !is_array($params["userIds"])) {
            throw new \Exception("forbidUser 参数错误!");
        }
        // 禁言
        $chartId = $this->_info["chatroom_group_id"];

        $tim = new TImService();
        if ($params["time"] == 0) {
            // 解禁
            $tim->redis_relieve_silence_msg($chartId, $params['user']['id']);
        } else {
            // 禁言
            $tim->redis_set_silence_msg($chartId, $params['user']);
        }
        $tim->redis_set_online_msg($chartId, $params['user']['no'], $params['user']);
        $ret = $tim->forbid_some_user_with_times($chartId, $params["userIds"], $params["time"]);
        if ($ret) {
            return true;
        } else {
            throw new \Exception("发生错误!");

        }
    }

    public function sendMsg($param)
    {
        // 数字人评论 mongo入库
        MarketionService::addOrEdit($param);

        $chartId = $this->_info["chatroom_group_id"];
        $tim = new TImService();
        $ret = $tim->message_normal_send_to_group($chartId, $param["msg"], $param["identifier"]);
        if ($ret !== true) {
            throw new \Exception($ret);
        }
    }

    public function sendCommand($param)
    {
        $chartId = $this->_info["chatroom_group_id"];
        $tim = new TImService();
        $ret = $tim->message_system_notify_send_to_group($chartId, json_encode($param));
        if ($ret !== true) {
            throw new \Exception($ret);
        }

    }
    public function customStatus($params)
    {

        if (empty($params["key"])) {
            throw new \Exception(" customStatus key not found");
        }
        if (!isset($params["value"])) {
            throw new \Exception(" customStatus key not found");
        }

        $Key = $params["key"];
        $value = $params["value"];

        $key = $this->getLiveKey($this->_liveId);
        return $this->_redis->hset($key, $Key, json_encode($value));

    }

    public function setDefaultStatus($defaultValue = [], $count = 0)
    {
        $key = $this->getLiveKey($this->_liveId);
        if ($count == 0) {
            $count = rand(100, 9000);
        }

        $this->setLikely($this->_liveId, $count);
        // $this->_info->toArray()
        return $this->_redis->hmset($key, array_merge($defaultValue, [
            "showPopCard" => "0", // 显示弹卡
            "showPopUp" => "0", //显示弹窗
            "showHotSale" => "0", // 显示热卖
            "showStock" => "0", // 显示库存
            "showNickName" => "0", // 显示昵称
            "showOnlineCount" => "0", // 显示在线人数
            "showLittleYellowCar" => "0", // 显示小黄车
            "showCourseSellStatus"=>"0", //显示商品已售罄
            
            "showDigitMan" => "0", // 隐藏数字人/评论组
            "showAllSilence" => "0", // 全体禁言
            "sendXiaoHeiBan" => "0", // 小黑板
        ]));
    }

    public function cleanStatus()
    {
        $key = $this->getLiveKey($this->_liveId);
        return $this->_redis->del($key);
    }

    public function showPopCard($param)
    {
        // 显示/隐藏弹卡 mongo入库
        MarketionService::addOrEdit($param);

        $key = $this->getLiveKey($this->_liveId);
        return $this->_redis->hset($key, "showPopCard", json_encode($param));
    }

    public function showPopUp($param)
    {
        // 显示/隐藏弹卡 mongo入库
        MarketionService::addOrEdit($param);

        $key = $this->getLiveKey($this->_liveId);
        return $this->_redis->hset($key, "showPopUp", json_encode($param));
    }

    public function showHotSale($param)
    {
        // 显示热卖 mongo入库
        MarketionService::addOrEdit($param);

        $key = $this->getLiveKey($this->_liveId);
        return $this->_redis->hset($key, "showHotSale", json_encode($param));
    }

    public function showStock($param)
    {
        // 显示仅剩库存 mongo入库
        MarketionService::addOrEdit($param);

        $key = $this->getLiveKey($this->_liveId);
        return $this->_redis->hset($key, "showStock", json_encode($param));
    }

    public function showOnlineCount($param)
    {
        // 设置初始在线人数 mongo入库
        MarketionService::addOrEdit($param);

        $key = $this->getLiveKey($this->_liveId);
        return $this->_redis->hset($key, "showOnlineCount", json_encode($param));
    }

    public function showNickName($param)
    {
        // 显示/隐藏昵称 mongo入库
        MarketionService::addOrEdit($param);

        $key = $this->getLiveKey($this->_liveId);
        return $this->_redis->hset($key, "showNickName", json_encode($param));
    }

    public function showLittleYellowCar($param)
    {
        // 显示/隐藏小黄车 mongo入库
        MarketionService::addOrEdit($param);

        $key = $this->getLiveKey($this->_liveId);
        return $this->_redis->hset($key, "showLittleYellowCar", json_encode($param));
    }
    //发送抽奖信息
    public function ChoujiangStatus($param)
    {
        // 显示/隐藏福袋 mongo入库
        MarketionService::addOrEdit($param);
        $key = $this->getLiveKey($this->_liveId);
        return $this->_redis->hset($key, "ChoujiangStatus", json_encode($param));
    }
    //发送开奖信息
    public function KaiJiangStatus($param)
    {
        MarketionService::addOrEdit($param);
        $key = $this->getLiveKey($this->_liveId);
        return $this->_redis->hset($key, "KaiJiangStatus", json_encode($param));
    }
    //手动结束抽奖
    public function FinishStatus($param)
    {
        MarketionService::addOrEdit($param);
        $key = $this->getLiveKey($this->_liveId);
        return $this->_redis->hset($key, "FinishStatus", json_encode($param));
    }
    public function showCourseSellStatus($param)
    {
        // 显示/隐藏商品销售是否售罄 mongo入库
        //MarketionService::addOrEdit($param);
        $key = $this->getLiveKey($this->_liveId);
        $val = $this->_redis->hget($key, 'showCourseSellStatus');
        if ($val == '0' || empty($val)) {
            return $this->_redis->hset($key, "showCourseSellStatus", json_encode([$param]));
        } else {
            $val = json_decode($val, true);
            $is = true;
            foreach ($val as &$v) {
                if ($v['goodsId'] == $param['goodsId']) {
                    $v = $param;
                    $is = false;
                }
            }
            if ($is) {
                $val[] = $param;
            }
            return $this->_redis->hset($key, "showCourseSellStatus", json_encode($val));
        }
    }
    public function showDigitMan($param)
    {
        // 显示/隐藏数字人/评论组
        //MarketionService::addOrEdit($param);

        $key = $this->getLiveKey($this->_liveId);
        return $this->_redis->hset($key, "showDigitMan", json_encode($param));
    }

    /***************************    ↓↓↓↓↓↓↓↓      数据统计     ↓↓↓↓↓↓↓↓↓     *********************************** */

    /////  存储

    public function set_live_starttime($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':live_starttime';
        return $this->_redis->set($key, $param);
    }

//已付款
    public function set_xiaoshoue_yifukuan($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiaoshoue_yifukuan';
        return $this->_redis->INCRBY($key, $param);
    }

    public function set_xiadan_rensu_yifukuan($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiadan_rensu_yifukuan';
        return $this->_redis->SADD($key, $param);
    }

    public function set_xiadan_danshu_yifukuan($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiadan_danshu_yifukuan';
        return $this->_redis->SADD($key, $param);
    }

//未付款
    public function set_xiaoshoue_weifukuan($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiaoshoue_weifukuan';
        return $this->_redis->INCRBY($key, $param);
    }

    public function set_xiadan_renshu_weifukuan($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiadan_renshu_weifukuan';
        return $this->_redis->SADD($key, $param);
    }

    public function set_xiadan_danshu_weifukuan($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiadan_danshu_weifukuan';
        return $this->_redis->SADD($key, $param);
    }

//退款
    public function set_xiaoshoue_tuikuan($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiaoshoue_tuikuan';
        return $this->_redis->INCRBY($key, $param);
    }

    public function set_xiadan_renshu_tuikuan($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiadan_renshu_tuikuan';
        return $this->_redis->SADD($key, $param);
    }

    public function set_xiadan_danshu_tuikuan($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiadan_danshu_tuikuan';
        return $this->_redis->SADD($key, $param);
    }

    public function set_guankan_renshu($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':guankan_renshu';
        return $this->_redis->SADD($key, $param);
    }

    public function set_zhiboshichang($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':zhiboshichang';
        return $this->_redis->set($key, $param);
    }

    public function set_dianji_shangpin_renshu($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':dianji_shangpin_renshu';
        return $this->_redis->SADD($key, $param);
    }

    public function set_dianji_shangpin_cishu($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':dianji_shangpin_cishu';
        return $this->_redis->lpush($key, $param);
    }

    ///    移除数据

    public function remove_xiaoshoue_weifukuan($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiaoshoue_weifukuan';
        $this->_redis->DECRBY($key, $param);
    }

    public function remove_xiadan_renshu_weifukuan($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiadan_renshu_weifukuan';
        $this->_redis->srem($key, $param);
    }

    public function remove_xiadan_danshu_weifukuan($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiadan_danshu_weifukuan';
        $this->_redis->srem($key, $param);
    }

    ///////  获取

    public function get_live_starttime()
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':live_starttime';
        return $this->_redis->get($key);
    }


    public function get_live_endtime()
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':live_endtime';
        return $this->_redis->get($key);
    }


    public function set_live_endtime($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':live_endtime';
        return $this->_redis->set($key, $param);
    }

    //已付款
    public function get_xiaoshoue_yifukuan()
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiaoshoue_yifukuan';
        return $this->_redis->get($key);
    }

    public function get_xiadan_rensu_yifukuan()
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiadan_rensu_yifukuan';
        return $this->_redis->SCARD($key);
    }

    public function get_xiadan_danshu_yifukuan()
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiadan_danshu_yifukuan';
        return $this->_redis->SCARD($key);
    }

    //未付款
    public function get_xiaoshoue_weifukuan()
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiaoshoue_weifukuan';
        return $this->_redis->get($key);
    }

    public function get_xiadan_renshu_weifukuan()
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiadan_renshu_weifukuan';
        return $this->_redis->SCARD($key);
    }

    public function get_xiadan_danshu_weifukuan()
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiadan_danshu_weifukuan';
        return $this->_redis->SCARD($key);
    }

    //退款
    public function get_xiaoshoue_tuikuan()
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiaoshoue_tuikuan';
        return $this->_redis->get($key);
    }

    public function get_xiadan_renshu_tuikuan()
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiadan_renshu_tuikuan';
        return $this->_redis->SCARD($key);
    }

    public function get_xiadan_danshu_tuikuan()
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':xiadan_danshu_tuikuan';
        return $this->_redis->SCARD($key);
    }

    public function get_guankan_renshu()
    {
        $key = env("redis.prefix") . 'live:list:' . $this->_liveId . ':online_user:map';
        return $this->_redis->hlen($key);
    }

    public function get_dianji_shangpin_renshu()
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':dianji_shangpin_renshu';
        return $this->_redis->SCARD($key);
    }

    public function get_dianji_shangpin_cishu()
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':dianji_shangpin_cishu';
        return $this->_redis->LLEN($key);
    }

    public function get_pingjun_guankan_shichang()
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':pingjun_guankan_shichang';
        return $this->_redis->get($key);
    }

    public function set_pingjun_guankan_shichang($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':pingjun_guankan_shichang';
        return $this->_redis->set($key, $param);
    }

    public function get_zong_guankan_shichang()
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':zong_guankan_shichang';
        return $this->_redis->get($key);
    }

    public function set_zong_guankan_shichang($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':zong_guankan_shichang';
        return $this->_redis->INCRBY($key, $param);
    }


    public function get_zhibo_leiji_shichang()
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':zhibo_leiji_shichang';
        return $this->_redis->get($key);
    }

    public function set_zhibo_leiji_shichang($param)
    {
        $key = env("redis.prefix") . 'tongji:' . $this->_liveId . ':zhibo_leiji_shichang';
        return $this->_redis->set($key, $param);
    }

    /***************************    ↑↑↑↑↑↑↑      数据统计     ↑↑↑↑↑↑↑     *********************************** */

    public function set_dabiaoqian_live($value)
    {
        $key = env("redis.prefix") . 'siyu_dabiaoqian';
        return $this->_redis->lpush($key, $value);
    }

    public function get_dabiaoqian_live()
    {
        $key = env("redis.prefix") . 'siyu_dabiaoqian';
        return $this->_redis->brpop($key,10);
    }

    /***************************  ↓↓↓↓↓↓  从聚水潭拉单  ↓↓↓↓↓↓   *********************************** */

    public function set_sph_order($value)
    {
        $key = env("redis.prefix").'shipinhao:shipinhao_orders';
        return $this->_redis->lpush($key, $value);
    }

    public function get_sph_order()
    {
        $key = env("redis.prefix").'shipinhao:shipinhao_orders';
        return $this->_redis->brpop($key, 20);
    }

    public function set_sph_cancel_order($value)
    {
        $key = env("redis.prefix").'shipinhao:shipinhao_cancel_orders';
        return $this->_redis->lpush($key, $value);
    }

    public function get_sph_cancel_order()
    {
        $key = env("redis.prefix").'shipinhao:shipinhao_cancel_orders';
        return $this->_redis->brpop($key, 20);
    }

    /***************************  ↓↓↓↓↓↓  从聚水潭拉单  ↓↓↓↓↓↓   *********************************** */

    public function set_jst_order($value)
    {
        $key = env("redis.prefix").'jushuitan:jushuitan_orders';
        return $this->_redis->lpush($key, $value);
    }

    public function get_jst_order()
    {
        $key = env("redis.prefix").'jushuitan:jushuitan_orders';
        return $this->_redis->brpop($key, 20);
    }

    public function set_jst_cancel_order($value)
    {
        $key = env("redis.prefix").'jushuitan:jushuitan_cancel_orders';
        return $this->_redis->lpush($key, $value);
    }

    public function get_jst_cancel_order()
    {
        $key = env("redis.prefix").'jushuitan:jushuitan_cancel_orders';
        return $this->_redis->brpop($key, 20);
    }


    //晚上  补漏


    public function set_jst_order_bulou($value)
    {
        $key = env("redis.prefix").'jushuitan:jushuitan_orders_bulou';
        return $this->_redis->lpush($key, $value);
    }

    public function get_jst_order_bulou()
    {
        $key = env("redis.prefix").'jushuitan:jushuitan_orders_bulou';
        return $this->_redis->brpop($key, 20);
    }

    public function set_jst_cancel_order_bulou($value)
    {
        $key = env("redis.prefix").'jushuitan:jushuitan_cancel_orders_bulou';
        return $this->_redis->lpush($key, $value);
    }

    public function get_jst_cancel_order_bulou()
    {
        $key = env("redis.prefix").'jushuitan:jushuitan_cancel_orders_bulou';
        return $this->_redis->brpop($key, 20);
    }


    /***************************  ↑↑↑↑↑↑  从聚水潭拉单  ↑↑↑↑↑↑   *********************************** */


    /***********************************     ↓↓↓↓↓ 打标签 ↓↓↓↓↓              ********************************* */

    public function set_jst_dabiaoqain($value)
    {
        $key = env("redis.prefix").'jushuitan:dabiaoqain';
        return $this->_redis->lpush($key, $value);
    }

    public function get_jst_dabiaoqain()
    {
        $key = env("redis.prefix").'jushuitan:dabiaoqain';
        return $this->_redis->brpop($key, 20);
    }

    /***************************  ↑↑↑↑↑↑  打标签  ↑↑↑↑↑↑   *********************************** */

}
